#!/usr/bin/perl
use modules::encode;
use strict;
package csseturl;

sub csseturl {

    my ($dbh,$remote,$input,$csnum) = @_;
    my $sth;my $auth;

   
    if ($$input[4] eq "") {
	print $remote "$csnum O $$input[0] :Syntax :SETURL <channel> [URL]\n";
    }
    else {
    
  	$sth=$dbh->prepare("SELECT auth FROM ninfo WHERE num = '$$input[0]' AND code = '".encode::encode($$input[0])."';");
	$sth->execute;
	if (!($auth=$sth->fetchrow_array)) {
	    print $remote "$csnum O $$input[0] :You must identify yourself with nickserv first.\n";
	}
	else {
	    $sth=$dbh->prepare("SELECT level FROM users WHERE channel = '$$input[4]' AND level = 500 AND rnick = '$auth';");
	    $sth->execute;
	    if (!$sth->fetchrow_array) {
		print $remote "$csnum O $$input[0] :Access denied.\n";
	    }
	    elsif ($$input[5] eq "") {
		print $remote "$csnum O $$input[0] :URL in $$input[4] set blanked.\n";
	    }
	    else {
		print $remote "$csnum O $$input[0] :Set $$input[4] URL to \cB$$input[5].\n";
		$sth=$dbh->prepare("UPDATE channels SET url = '$$input[5]' WHERE channel = '$$input[4]';");
		$sth->execute;
	    }

	}
    }
}
1;
